a = [100, 200, 120, 80, 50, 150, 20, 160, 90, 130]
ranges = []

ranges.append((0, len(a) - 1))

while len(ranges) > 0:
    left, right = ranges[0]
    t = left
    ranges = ranges[1:]
    i = left
    j = right
    while(i != j):
        while(a[j] >= a[t] and i < j):
            j -= 1
        while(a[i] <= a[t] and i < j):
            i += 1
        if i < j:
            a[i], a[j] = a[j], a[i]

    a[t], a[i] = a[i], a[t]
    if left < i - 1:
        ranges.append((left, i - 1))

    if i + 1 < right:
        ranges.append((i + 1, right))

print(a)
    
